package com.qlh.camera.voice

import com.jacob.activeX.ActiveXComponent
import com.jacob.com.Dispatch
import com.jacob.com.Variant
import io.reactivex.Flowable
import io.reactivex.schedulers.Schedulers

object PlayVoiceHelper {

    //拿到音响
    private val sap by lazy {
        ActiveXComponent("Sapi.SpVoice")
    }

    fun playText(msg: String = "hello") {
        val xj = sap.`object`
        val d = sap.getProperty("voice").toDispatch()
        val t = Dispatch.call(d, "GetDescription")
        println("$t")
        sap.apply {
            setProperty("Volume", Variant(100))
            setProperty("Rate", Variant(0))
        }
        Flowable.just(1)
                .observeOn(Schedulers.newThread())
                .subscribe {
                    Dispatch.call(xj, "Speak", Variant(msg))
                }
        //xj.safeRelease()
    }


    fun release() {
        sap.`object`.safeRelease()
        sap.safeRelease()
    }
}